package com.wlzg.collectiontool.adapter

import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.wlzg.collectiontool.R
import com.wlzg.collectiontool.model.bean.PsHunjie

internal class GuandianAdapter() :
    BaseQuickAdapter<PsHunjie?, BaseViewHolder>(
        R.layout.item_guandiandia

    ) {


    override fun convert(helper: BaseViewHolder, item: PsHunjie?) {
        helper.setIsRecyclable(false)
        Glide.with(context)
            .load(item?.image1).placeholder(R.mipmap.zahopian)
            .centerCrop()
            .into(helper.getView(R.id.iamge1))
        Glide.with(context)
            .load(item?.image2).placeholder(R.mipmap.zahopian)
            .centerCrop()
            .into(helper.getView(R.id.iamge2))
        Glide.with(context)
            .load(item?.image3).placeholder(R.mipmap.zahopian)
            .centerCrop()
            .into(helper.getView(R.id.iamge3))
        helper.setText(R.id.hjssbianhao, item?.hybridcode)
        helper.setText(R.id.hjssleixing, item?.problemType.toString())
        helper.setText(R.id.hjjleibie, item?.mixpointCatogery.toString())
        helper.setText(R.id.sybianhao, item?.upstreamNumber)
        helper.setText(R.id.hjlaiyuan, item?.hjsource.toString())
        helper.setText(R.id.hjgj, item?.pipDiameter.toString())
        helper.setText(R.id.hjweizhi, item?.locationcode)
        helper.setText(R.id.hjyuanyin, item?.hybRason)


//        helper.setText(R.id.hjgj, item?.pipDiameter.toString())
//        helper.setText(R.id.hjweizhi, item?.hybLocation)
//        helper.setText(R.id.hjyuanyin, item?.hybRason)
//        helper.setText(R.id.hjshuizhi, item?.waterquality)
//        helper.setText(R.id.zgfangan, item?.plan)
        helper.getView<EditText>(R.id.hjssbianhao).addTextChangedListener(MWatcher(item, 1))
        helper.getView<EditText>(R.id.hjssleixing).addTextChangedListener(MWatcher(item, 2))
        helper.getView<EditText>(R.id.hjjleibie).addTextChangedListener(MWatcher(item, 3))
        helper.getView<EditText>(R.id.sybianhao).addTextChangedListener(MWatcher(item, 4))
        helper.getView<EditText>(R.id.hjlaiyuan).addTextChangedListener(MWatcher(item, 5))
        helper.getView<EditText>(R.id.hjgj).addTextChangedListener(MWatcher(item, 6))
        helper.getView<EditText>(R.id.hjweizhi).addTextChangedListener(MWatcher(item, 7))
        helper.getView<EditText>(R.id.hjyuanyin).addTextChangedListener(MWatcher(item, 8))

    }

    class MWatcher(var item: PsHunjie?, var type: Int) : TextWatcher {
        override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

        }

        override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

        }

        override fun afterTextChanged(p0: Editable?) {
            try {
                when (type) {
                    1 -> {
                        item?.hybridcode = p0.toString()
                    }
                    2 -> {
                        try {
                            item?.problemType = p0.toString().toInt()
                        } catch (e: NumberFormatException) {
                            e.printStackTrace()
                        }
                    }
                    3 -> {
                        try {
                            item?.mixpointCatogery = p0.toString().toInt()
                        } catch (e: NumberFormatException) {
                            e.printStackTrace()
                        }
                    }
                    4 -> {
                        item?.upstreamNumber = p0.toString()
                    }
                    5 -> {
                        try {
                            item?.hjsource = p0.toString()
                        } catch (e: NumberFormatException) {
                            e.printStackTrace()
                        }
                    }
                    6 -> {
                        item?.pipDiameter = p0.toString().toInt()
                    }
                    7 -> {
                        item?.locationcode = p0.toString()
                    }
                    8 -> {
                        item?.hybRason = p0.toString()
                    }

                }
            } catch (e: NumberFormatException) {
                e.printStackTrace()
            }
        }

    }


}